package com.kang.topic;

import com.kang.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 可适用于登陆注册等功能
 */
public class Provider {

    //生产消息
    public static void main(String[] args) throws IOException, TimeoutException {
        //通过工具类获取连接对象
        Connection connection = RabbitMQUtils.getConnection();
        //获取连接中通道
        Channel channel = connection.createChannel();
        //将通道声明指定的交换机
        //参数1：交换机名称     参数2：交换机类型       fanout：广播类型
        channel.exchangeDeclare("topics", "topic");

        //发布消息
        String routeKey = "user.save";
        channel.basicPublish("topics", routeKey, null, "topic message".getBytes());

        //释放资源
        RabbitMQUtils.closeConnectionAndChanel(channel, connection);
    }
}
